//
//  TopAll.m
//  LilyBBS
//
//  Created by 李行 on 11-11-5.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "TopAll.h"
#import "xpath.h"
#import "Top10Detail.h"
#import "Detail.h"
#import "Reachability.h"

@implementation TopAll

@synthesize sectiontitle,cells,siteData,xpathParser,i,contentView,activityIndicator;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    viewdidloadcount = 0;
    viewdidappear = YES;
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView
 {
 }
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    /*UIActivityIndicatorView* indicatorView=[[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    indicatorView.center=CGPointMake(160,160);
    [self.tableView addSubview:indicatorView];
    [indicatorView startAnimating];*/
    
    viewdidloadcount++;
    self.title = @"各区热点";
    self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque; 
    self.tableView.rowHeight = 70;
    NSMutableArray* tmpArray = [[NSMutableArray alloc] initWithObjects:@"本站系统",@"南京大学",@"乡情校谊",@"电脑技术",@"学术科学",@"文化艺术",@"体育娱乐",@"感性休闲",@"新闻信息",@"百合广角",@"校务信箱",@"社团群体", nil];
    self.sectiontitle = tmpArray;
    [tmpArray release];
    
    if (_refreshHeaderView == nil) {
        EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
        view.delegate = self;
        [self.tableView addSubview:view];
        _refreshHeaderView = view;
        [view release];
        
    }
    //  update the last update date
    [_refreshHeaderView refreshLastUpdatedDate];
    if (!(viewdidloadcount == 1)) {//第一次加载时不进行此步骤
        [self getDetail];
    }
    [super viewDidLoad];
}

-(void)viewWillAppear:(BOOL)animated{
    Reachability *r = [Reachability reachabilityWithHostName:@"www.nju.edu.cn"];
    switch ([r currentReachabilityStatus]) {
        case NotReachable:
            //没有网络连接
            NSLog(@" ");
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络好像连接不上。。。" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [alert show];
            [alert release];
            return;
        case ReachableViaWWAN:
            //使用3G网络            
            break;
        case ReachableViaWiFi:
            // 使用WiFi网络            
            break;
    }
}

-(void)viewDidAppear:(BOOL)animated{
    if (viewdidappear) {//第一次加载时进行此步骤
        [self getDetail];
        [self.tableView reloadData];
    }
    viewdidappear = NO;
}


- (void)viewDidUnload
{
    _refreshHeaderView=nil;
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

// Section Titles
//每个section显示的标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    return [self.sectiontitle objectAtIndex:section];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
#warning Potentially incomplete method implementation.
    // Return the number of sections.
    //return [self.sectiontitle count];
    return [self.cells count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
#warning Incomplete method implementation.
    // Return the number of rows in the section.
    return [[[self.cells objectAtIndex:section] objectAtIndex:1] count];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    // Navigation logic may go here. Create and push another view controller.
    Reachability *r = [Reachability reachabilityWithHostName:@"www.nju.edu.cn"];
    switch ([r currentReachabilityStatus]) {
        case NotReachable:
            //没有网络连接
            NSLog(@" ");
            UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"网络好像连接不上。。。" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:nil];
            [alert show];
            [alert release];
            return;
        case ReachableViaWWAN:
            //使用3G网络            
            break;
        case ReachableViaWiFi:
            // 使用WiFi网络            
            break;
    }
    
    Detail* webView = [[Detail alloc] initWithNibName:@"Detail" bundle:nil];
    NSString* href = [[@"http://bbs.nju.edu.cn/" stringByAppendingString:[[[self.cells objectAtIndex:indexPath.section] objectAtIndex:2] objectAtIndex:indexPath.row]]stringByAppendingFormat:@"&start=-1"];
    //NSURL* url = [[NSURL alloc] initWithString:href];
    //NSData* data = [[NSData alloc] initWithContentsOfURL:url];
    //[webView getDetail:data];
    webView.titlestring = [[[self.cells objectAtIndex:indexPath.section] objectAtIndex:0] objectAtIndex:indexPath.row];
    webView.urlString = [NSString stringWithString:href];
    [self.navigationController pushViewController:webView animated:YES];
    
    /*Top10Detail *detailViewController = [[Top10Detail alloc] initWithNibName:@"Top10" bundle:nil];
    NSString* i = @"http://bbs.nju.edu.cn/";
    NSString* href = [[i stringByAppendingString:[[[self.cells objectAtIndex:indexPath.section] objectAtIndex:2] objectAtIndex:indexPath.row]]stringByAppendingFormat:@"&start=-1"];
    detailViewController.urlString = [NSString stringWithString:href];
    NSURL* url = [[NSURL alloc] initWithString:href];
    NSData* data = [[NSData alloc] initWithContentsOfURL:url];
    [detailViewController getDetail:data];
    detailViewController.titlestring = [[[self.cells objectAtIndex:indexPath.section] objectAtIndex:0] objectAtIndex:indexPath.row];
    // ...
    // Pass the selected object to the new view controller.
    [self.navigationController pushViewController:detailViewController animated:YES];
    [detailViewController release];*/
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    [cell.textLabel setNumberOfLines:2];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Configure the cell...
    cell.textLabel.text = [[[self.cells objectAtIndex:indexPath.section] objectAtIndex:0] objectAtIndex:indexPath.row];
    NSString* board = @"讨论区：";
    cell.detailTextLabel.text = [board stringByAppendingString:[[[[cells objectAtIndex:indexPath.section] objectAtIndex:1]objectAtIndex:indexPath.row]description]];
    
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    return cell;
}

- (void) getDetail{
    //生成的array结构为：topall(boards1,boards2,... boards12),每一个boards里的结构：boards1(titles,boards,hrefs)
    
    self.siteData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:TOP_ALL]];
	self.xpathParser = [[TFHpple alloc] initWithHTMLData:siteData];
    [siteData release];
    
    NSMutableArray* boards = [[[NSMutableArray alloc] init]autorelease];//存储版块名
    NSMutableArray* titles = [[[NSMutableArray alloc] init]autorelease];//存储主题名
    NSMutableArray* hrefs =  [[[NSMutableArray alloc] init]autorelease];//存储链接
    
	NSMutableArray * boards1 = [[NSMutableArray alloc] init];//本站系统
    NSMutableArray * boards2 = [[NSMutableArray alloc] init];
    NSMutableArray * boards3 = [[NSMutableArray alloc] init];
    NSMutableArray * boards4 = [[NSMutableArray alloc] init];
    NSMutableArray * boards5 = [[NSMutableArray alloc] init];
    NSMutableArray * boards6 = [[NSMutableArray alloc] init];
    NSMutableArray * boards7 = [[NSMutableArray alloc] init];
    NSMutableArray * boards8 = [[NSMutableArray alloc] init];
    NSMutableArray * boards9 = [[NSMutableArray alloc] init];
    NSMutableArray * boards10 = [[NSMutableArray alloc] init];
    NSMutableArray * boards11 = [[NSMutableArray alloc] init];
    NSMutableArray * boards12 = [[NSMutableArray alloc] init];
	
    NSMutableArray* arr = [[NSMutableArray alloc] init];//将所有array集成
    
    //将“本站系统”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL1_TITLE];
    NSMutableArray* titlesarr1 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr1 addObject:strs];
    }
    [boards1 addObject:titlesarr1];
    [titlesarr1 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL1_BOARD];
    NSMutableArray* boardsarr1 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr1 addObject:strs];
    }
    [boards1 addObject:boardsarr1];
    [boardsarr1 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL1_HREF];
    NSMutableArray* hrefsarr1 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr1 addObject:strs];
    }
    [boards1 addObject:hrefsarr1];
    [hrefsarr1 release];
    [arr addObject:boards1];
    
    
    
    //将“南京大学”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL2_TITLE];
    NSMutableArray* titlesarr2 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr2 addObject:strs];
    }
    [boards2 addObject:titlesarr2];
    [titlesarr2 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL2_BOARD];
    NSMutableArray* boardsarr2 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr2 addObject:strs];
    }
    [boards2 addObject:boardsarr2];
    [boardsarr2 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL2_HREF];
    NSMutableArray* hrefsarr2 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr2 addObject:strs];
    }
    [boards2 addObject:hrefsarr2];
    [hrefsarr2 release];
    [arr addObject:boards2];
    
    //将“乡情校谊”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL3_TITLE];
    NSMutableArray* titlesarr3 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr3 addObject:strs];
    }
    [boards3 addObject:titlesarr3];
    [titlesarr3 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL3_BOARD];
    NSMutableArray* boardsarr3 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr3 addObject:strs];
    }
    [boards3 addObject:boardsarr3];
    [boardsarr3 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL3_HREF];
    NSMutableArray* hrefsarr3 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr3 addObject:strs];
    }
    [boards3 addObject:hrefsarr3];
    [hrefsarr3 release];
    [arr addObject:boards3];
    
    //将“电脑技术”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL4_TITLE];
    NSMutableArray* titlesarr4 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr4 addObject:strs];
    }
    [boards4 addObject:titlesarr4];
    [titlesarr4 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL4_BOARD];
    NSMutableArray* boardsarr4 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr4 addObject:strs];
    }
    [boards4 addObject:boardsarr4];
    [boardsarr4 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL4_HREF];
    NSMutableArray* hrefsarr4 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr4 addObject:strs];
    }
    [boards4 addObject:hrefsarr4];
    [hrefsarr4 release];
    [arr addObject:boards4];
    
    //将“学术学科”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL5_TITLE];
    NSMutableArray* titlesarr5 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr5 addObject:strs];
    }
    [boards5 addObject:titlesarr5];
    [titlesarr5 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL5_BOARD];
    NSMutableArray* boardsarr5 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr5 addObject:strs];
    }
    [boards5 addObject:boardsarr5];
    [boardsarr5 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL5_HREF];
    NSMutableArray* hrefsarr5 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr5 addObject:strs];
    }
    [boards5 addObject:hrefsarr5];
    [hrefsarr5 release];
    [arr addObject:boards5];
    
    //将“文化艺术”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL6_TITLE];
    NSMutableArray* titlesarr6 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr6 addObject:strs];
    }
    [boards6 addObject:titlesarr6];
    [titlesarr6 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL6_BOARD];
    NSMutableArray* boardsarr6 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr6 addObject:strs];
    }
    [boards6 addObject:boardsarr6];
    [boardsarr6 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL6_HREF];
    NSMutableArray* hrefsarr6 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr6 addObject:strs];
    }
    [boards6 addObject:hrefsarr6];
    [hrefsarr6 release];
    [arr addObject:boards6];
    
    //将“体育娱乐”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL7_TITLE];
    NSMutableArray* titlesarr7 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr7 addObject:strs];
    }
    [boards7 addObject:titlesarr7];
    [titlesarr7 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL7_BOARD];
    NSMutableArray* boardsarr7 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr7 addObject:strs];
    }
    [boards7 addObject:boardsarr7];
    [boardsarr7 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL7_HREF];
    NSMutableArray* hrefsarr7 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr7 addObject:strs];
    }
    [boards7 addObject:hrefsarr7];
    [hrefsarr7 release];
    [arr addObject:boards7];
    
    //将“感性新闻”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL8_TITLE];
    NSMutableArray* titlesarr8 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr8 addObject:strs];
    }
    [boards8 addObject:titlesarr8];
    [titlesarr8 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL8_BOARD];
    NSMutableArray* boardsarr8 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr8 addObject:strs];
    }
    [boards8 addObject:boardsarr8];
    [boardsarr8 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL8_HREF];
    NSMutableArray* hrefsarr8 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr8 addObject:strs];
    }
    [boards8 addObject:hrefsarr8];
    [hrefsarr8 release];
    [arr addObject:boards8];
    
    //将“新闻信息”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL9_TITLE];
    NSMutableArray* titlesarr9 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr9 addObject:strs];
    }
    [boards9 addObject:titlesarr9];
    [titlesarr9 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL9_BOARD];
    NSMutableArray* boardsarr9 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr9 addObject:strs];
    }
    [boards9 addObject:boardsarr9];
    [boardsarr9 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL9_HREF];
    NSMutableArray* hrefsarr9 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr9 addObject:strs];
    }
    [boards9 addObject:hrefsarr9];
    [hrefsarr9 release];
    [arr addObject:boards9];
    
    //将“百合广角”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL10_TITLE];
    NSMutableArray* titlesarr10 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr10 addObject:strs];
    }
    [boards10 addObject:titlesarr10];
    [titlesarr10 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL10_BOARD];
    NSMutableArray* boardsarr10 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr10 addObject:strs];
    }
    [boards10 addObject:boardsarr10];
    [boardsarr10 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL10_HREF];
    NSMutableArray* hrefsarr10 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr10 addObject:strs];
    }
    [boards10 addObject:hrefsarr10];
    [hrefsarr10 release];
    [arr addObject:boards10];
    
    //将“校务信箱”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL11_TITLE];
    NSMutableArray* titlesarr11 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
		NSString *strs = [element content];
		[titlesarr11 addObject:strs];
    }
    [boards11 addObject:titlesarr11];
    [titlesarr11 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL11_BOARD];
    NSMutableArray* boardsarr11 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr11 addObject:strs];
    }
    [boards11 addObject:boardsarr11];
    [boardsarr11 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL11_HREF];
    NSMutableArray* hrefsarr11 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr11 addObject:strs];
    }
    [boards11 addObject:hrefsarr11];
    [hrefsarr11 release];
    [arr addObject:boards11];
    
    //将“社团群体”的主题、板块、链接取出
    titles = [xpathParser searchWithXPathQuery:TOP_ALL12_TITLE];
    NSMutableArray* titlesarr12 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in titles) {
        if ([element content]!=nil) {//有时会出现抓取错误，抓到nil的东西，比如特殊字符串
            NSString *strs = [element content];
            [titlesarr12 addObject:strs];
        }
    }
    [boards12 addObject:titlesarr12];
    [titlesarr12 release];
    
    boards = [xpathParser searchWithXPathQuery:TOP_ALL12_BOARD];
    NSMutableArray* boardsarr12 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in boards) {
		NSString *strs = [element content];
		[boardsarr12 addObject:strs];
    }
    [boards12 addObject:boardsarr12];
    [boardsarr12 release];
    
    hrefs = [xpathParser searchWithXPathQuery:TOP_ALL12_HREF];
    NSMutableArray* hrefsarr12 = [[NSMutableArray alloc] init];
	for (TFHppleElement *element in hrefs) {
		NSString *strs = [element content];
		[hrefsarr12 addObject:strs];
    }
    [boards12 addObject:hrefsarr12];
    [hrefsarr12 release];
    [arr addObject:boards12];
    
    
    self.cells = arr;
    /*[arr release];
     [boards1 release];
     [boards2 release];
     [boards3 release];
     [boards4 release];
     [boards5 release];
     [boards6 release];
     [boards7 release];
     [boards8 release];
     [boards9 release];
     [boards10 release];
     [boards11 release];
     [boards12 release];
     [boards release];
     [titles release];
     [hrefs release];*/
}

- (void)dealloc{
    _refreshHeaderView = nil;
    [sectiontitle release];
    [cells release];
    [super dealloc];
}

#pragma mark -
#pragma mark Data Source Loading / Reloading Methods

- (void)reloadTableViewDataSource{
    //  should be calling your tableviews data source model to reload
    //  put here just for demo
    _reloading = YES;
    [self getDetail];
}

- (void)doneLoadingTableViewData{
    //  model should call this when its done loading
    _reloading = NO;
    [_refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.tableView];
    [self.tableView reloadData];
}

#pragma mark -
#pragma mark UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    [_refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    [_refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
}

#pragma mark -
#pragma mark EGORefreshTableHeaderDelegate Methods

- (void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView*)view{
    [self performSelector:@selector(doneLoadingTableViewData) withObject:nil afterDelay:1.0];
}

- (BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView*)view{
    return _reloading; // should return if data source model is reloading
}

- (NSDate*)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView*)view{
    return [NSDate date]; // should return date data source was last changed
}

@end
